:root {
    /* === UI Button Size === */
    --btn-size: 36px;
}

#txt2img_size_toolbox,
#img2img_size_toolbox {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px !important;
}

/* Grid layout for img2img when there are 4+ buttons */
#img2img_size_toolbox:has(> :nth-child(4)) {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px !important;
}
#img2img_size_toolbox:has(> :nth-child(4)) > * {
    width: 100% !important;
}

/* Button Base Styles */
#txt2img_ratio select,
#img2img_ratio select,
#txt2img_presets_btn,
#img2img_presets_btn,
#txt2img_res_switch_btn,
#img2img_res_switch_btn,
#img2img_detect_image_size_btn {
    width: var(--btn-size) !important;
    min-width: var(--btn-size) !important;
    height: var(--btn-size) !important;
    max-height: var(--btn-size) !important;
    box-sizing: border-box !important;
}
#txt2img_ratio select:focus,
#img2img_ratio select:focus,
#txt2img_presets_btn:focus,
#img2img_presets_btn:focus {
    outline: none;
    box-shadow: none;
}

/* Ratio Select Styles */
#txt2img_ratio select,
#img2img_ratio select {
    appearance: none;
    padding: 0;
    font-size: 14px;
    line-height: var(--btn-size);
    text-align: center;
    text-align-last: center;
    color: var(--block-label-text-color);
    background: var(--background-fill-primary);
    background-image: none;
    border: 1px solid var(--block-border-color);
    border-radius: 8px;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    cursor: pointer;
}
#txt2img_ratio select:hover,
#img2img_ratio select:hover {
    background: var(--background-fill-secondary);
}

/* Presets Button */
#txt2img_presets_btn,
#img2img_presets_btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    width: 100%;
    background: var(--background-fill-primary);
    border: 1px solid var(--block-border-color);
    border-radius: 8px;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    cursor: pointer;
}
#txt2img_presets_btn:hover,
#img2img_presets_btn:hover {
    background: var(--background-fill-secondary);
}

#txt2img_presets_btn svg,
#img2img_presets_btn svg {
    fill: var(--block-label-text-color);
}

/* Popup Container */
.arp-presets-popup {
    position: absolute;
    min-width: 240px !important;
    width: max-content !important;
    background: var(--body-background-fill);
    border: 1px solid var(--border-color-primary);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    z-index: 1000;
    user-select: none;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Popup Header */
.arp-presets-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--block-background-fill);
    border-bottom: 1px solid var(--border-color-primary);
}

.arp-presets-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--body-text-color);
    margin: 0;
}

.arp-header-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.arp-presets-close,
.arp-presets-settings {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    color: var(--body-text-color-subdued);
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
}

.arp-presets-close svg,
.arp-presets-settings svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.arp-presets-close:hover,
.arp-presets-settings:hover {
    color: var(--body-text-color);
    background: var(--button-secondary-background-fill-hover);
}

/* Popup Content */
.arp-presets-content {
    max-height: 50vh;
    overflow-y: auto;
    padding: 16px;
}

/* Category Section */
.arp-presets-section {
    margin-bottom: 20px;
}
.arp-presets-section:last-child {
    margin-bottom: 0;
}

.arp-presets-section-label {
    font-size: 14px;
    font-weight: 400;
    color: var(--body-text-color);
    margin: 0 0 8px 0;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color-primary);
}

/* Presets Grid */
.arp-presets-grid {
    display: grid;
    gap: 6px;
}

/* Preset Button */
.arp-preset-btn {
    padding: 4px 8px !important;
    color: var(--body-text-color);
    font-size: 14px !important;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    background: var(--input-background-fill);
    border: 1px solid var(--input-border-color);
    border-radius: 4px;
    cursor: pointer;
}
.arp-preset-btn:hover {
    background: var(--button-primary-background-fill);
    border-color: var(--button-primary-border-color);
    color: var(--button-primary-text-color);
}

/* Temporary Auto Ratio - Highlight Select */
#txt2img_ratio select.ar-select-temp-active,
#img2img_ratio select.ar-select-temp-active {
    border-color: #f59e0b;
}

#txt2img_ratio select option.ar-option-temp,
#img2img_ratio select option.ar-option-temp {
    color: #f59e0b;
    font-style: italic;
    font-weight: 700;
}

/* Scrollbar */
.arp-presets-content::-webkit-scrollbar {
    width: 6px;
}
.arp-presets-content::-webkit-scrollbar-track {
    background: var(--body-background-fill);
}
.arp-presets-content::-webkit-scrollbar-thumb {
    background: var(--border-color-primary);
}
.arp-presets-content::-webkit-scrollbar-thumb:hover {
    background: var(--body-text-color-subdued);
}
